using System.Windows.Forms;
using System;
using System.Drawing;

namespace MyCalculator
{
    public partial class Form1 : Form
    {
        private UserControl currentControl;

        public Form1()
        {
            InitializeComponent();
            SwitchView(typeof(StandardCalculator));
        }

        //切换模式（标准/科学计算器）
        private void SwitchView(Type controlType)
        {
            if (currentControl?.GetType() == controlType) return;

            Controls.Remove(currentControl);
            currentControl?.Dispose();

            currentControl = (UserControl)Activator.CreateInstance(controlType);
            currentControl.Dock = DockStyle.Fill;

            Controls.Add(currentControl);
            currentControl.BringToFront();
        }

        // 菜单切换事件
        //基础计算器
        private void standardToolStripMenuItem_Click(object sender, EventArgs e)
            => SwitchView(typeof(StandardCalculator));

        //科学计算器
        private void scientificToolStripMenuItem_Click(object sender, EventArgs e)
            => SwitchView(typeof(ScientificCalculator));

    }
}